#!/usr/bin/python

from pylab import *
import sys
import os
# appends project's (maloqp) parent directory to python search path
sys.path.append(os.getcwd().rsplit(os.path.sep, 2)[0])
print os.getcwd().rsplit(os.path.sep, 2)[0]

import maloqp.src.mcc as mcc



#cutoffs = ['0', '0.5', '1', '1.5', '2', \
#          '2.5', '3', '3.5', '4', '4.5', \
#          '5', '5.5', '6', '6.5', '7', '7.5',\
#          '8', '8.5', '9', '9.5', '10']

#x = [-1*float(y) for y in cutoffs]

#ma = [0 for y in cutoffs]
#lo = [0 for y in cutoffs]
#qp = [0 for y in cutoffs]
ma_x = [0 for i in xrange(1, 102)]
lo_x = [0 for i in xrange(1, 102)]
qp_x = [0 for i in xrange(1, 102)]

ma_y = [0 for i in xrange(1, 102)]
lo_y = [0 for i in xrange(1, 102)]
qp_y = [0 for i in xrange(1, 102)]

no_of_samples = '200'
#sample = 'nosample'
sample = "sf"

for i in xrange(1, 102):
    file1 = "../data/roc/real"
    file2 = "../data/roc/ma/"+sample+str(i)
    file3 = "../data/roc/lo/"+sample+str(i)
    file4 = "../data/roc/qp/"+sample+str(i)
    ma_x[i] = (mcc.mcc(file1, file2, "--fptp"))[1] * 1.0 / (16384-584)
    lo_x[i] = (mcc.mcc(file1, file3, "--fptp"))[1] * 1.0 / (16384-584)
    qp_x[i] = (mcc.mcc(file1, file4, "--fptp"))[1] * 1.0 / (16384-584)
    
    ma_y[i] = (mcc.mcc(file1, file2, "--fptp"))[0] * 1.0 / (584)
    lo_y[i] = (mcc.mcc(file1, file3, "--fptp"))[0] * 1.0 / (584)
    qp_y[i] = (mcc.mcc(file1, file4, "--fptp"))[0] * 1.0 / (584)


#for i in xrange(len(cutoffs)):
#    file1 = "../data/"+sample+"/s"+cutoffs[i]
#    file2 = "../data/"+sample+"/ma"+cutoffs[i]
#    file3 = "../data/"+sample+"/lo"+cutoffs[i]
#    file4 = "../data/"+sample+"/qp"+cutoffs[i]
#    ma[i] += mcc.mcc(file1, file2)
#    lo[i] += mcc.mcc(file1, file3)
#    qp[i] += mcc.mcc(file1, file4)

## for i in xrange(len(cutoffs)):
##     for t in ['1', '2', '3']:
##         file1 = "../data/nosample/s"+cutoffs[i]
##         file2 = "../data/"+sample+"/ma"+cutoffs[i]+'_'+no_of_samples+'_'+t
##         file3 = "../data/"+sample+"/lo"+cutoffs[i]+'_'+no_of_samples+'_'+t
##         file4 = "../data/"+sample+"/qp"+cutoffs[i]+'_'+no_of_samples+'_'+t
##         ma[i] += mcc.mcc(file1, file2)
##         lo[i] += mcc.mcc(file1, file3)
##         qp[i] += mcc.mcc(file1, file4)

## for i in xrange(len(cutoffs)):
##     ma[i] /= 3
##     lo[i] /= 3
##     qp[i] /= 3

## print ma
## print lo
## print qp

plot(ma_x, ma_y, 'r-^', linewidth=2)
plot(lo_x, lo_y, 'b-s', linewidth=2)
plot(qp_x, qp_y, 'y-o', linewidth=2)

#axis([-10, 0, 0, 1])

legend(('Quadratic Programming', 'Log-Odds', 'Match'),loc='lower right')
xlabel('Energy')
ylabel('MCC')
title('Complete')
#axis([-10, 0, 1, 2500])
grid(True)
savefig("temp")
show()
